package com.roncoo.eshop.mapper;

import com.roncoo.eshop.model.ProductInventory;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

/**
 * 库存数量Mapper
 *
 * @author Administrator
 */
@Repository
public interface ProductInventoryMapper {

    /**
     * 更新库存数量
     *
     * @param Integer 商品库存
     */
    @Update("update product_inventory set inventory_cnt=#{productInventory.inventoryCnt} where product_id=#{productInventory.productId}")
    Integer updateProductInventory(@Param("productInventory") ProductInventory productInventory);

    /**
     * 根据商品id查询商品库存信息
     *
     * @param productId 商品id
     * @return 商品库存信息
     */
    @Select("select product_id ,inventory_cnt from product_inventory where product_id=#{productId}")
    @Results(id = "ProductInventory", value = {
            @Result(column = "id", property = "id"),
            @Result(column = "product_id", property = "productId"),
            @Result(column = "inventory_cnt", property = "inventoryCnt"),
    })
    ProductInventory findProductInventory(@Param("productId") Integer productId);

}
